import {
    ADD_COUNTER,
    ADD_TO_CART
} from './mutation-type'

export default{
    addCart({state,commit},payload){
       return new Promise((resolve,reject) => {
        let oldProduct = null;
        for(let item of state.cartList){
            if(item.iid === payload.iid){
                oldProduct = item
            }
        }
        if(oldProduct){
            commit(ADD_COUNTER,oldProduct)
            resolve('当前数量加1')
        }else{
            payload.count = 1
            // state.cartList.push(payload)
            commit(ADD_TO_CART,payload)
            resolve('添加新的商品')
        }
       })
    }
}